package com.example.cunwan_hd.Server;

import com.alibaba.fastjson.JSON;
import com.example.cunwan_hd.Mapper.UserMapper;
import com.example.cunwan_hd.Pojo.UserPojo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class UserService {
    @Autowired
    UserMapper usermapper;
    public Map  login(UserPojo userPojo){
        Map<String,Object> out =new HashMap<>();
       try {
           Map sql= usermapper.login(userPojo);

           if(sql.get("name").equals(userPojo.getName()) && sql.get("password").equals(userPojo.getPassword())){
              out.put("state","ok");
              out.put("name",sql.get("name"));
              return out;
           }else {
               out.put("state","no");
               return out;
           }
       }catch (Exception e){

           out.put("state","no");
           return out;
       }



    }

    public String register(UserPojo userojo) {
        if (userojo.getName().isEmpty() || userojo.getPassword().isEmpty()){


        }else {
            try {
                Map name=usermapper.login(userojo);
                usermapper.register(userojo);
                return "ok";
            }catch (Exception e){
                return "on";
            }

        }
        return "on";


    }
}
